﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

public partial class Controls_con_step : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void SetStep(int mid, String cname)
    {
        DBaccess db = new DBaccess();
        DataSet ds = new DataSet();
        DataSet ds1 = new DataSet();
        ds = db.GetDataSet("select * from mr_v_recommand where sid = '" + mid + "'");
        GVstep1.DataSource = ds;
        GVstep1.DataBind();
        ds1 = db.GetDataSet("select cid from mr_course where cname = '" + cname + "'");
        int cid = int.Parse(ds1.Tables[0].Rows[0]["cid"].ToString());
        LabelCoursename.Text = "课程号：" + cid + "  课程名:" + cname;
        String sql = "select * from mr_v_recommand where sid != '" + mid + "' and [" + cid + "] is not null";
        ds1 = db.GetDataSet(sql);
        GVstep2.DataSource = ds1;
        GVstep2.DataBind();
        MyVector MyVec = new MyVector(mid);
        ArrayList arr = MyVec.GetRank();
        int i, j;
        Label rank = new Label();
        rank.Width = 540;
        rank.Text = mid + ":{";
        for (i = 0; i < arr.Count; i++)
        {
            rank.Text += arr[i] + " ";
        }
        rank.Text += "}";
        PanelRank.Controls.Add(rank);
        DataSet ds2 = new DataSet();
        ds2 = db.GetDataSet("select value from mr_parameter where pname = 'sim'");
        for (i = 0; i < ds1.Tables[0].Rows.Count; i++)
        {
           
            int omid = int.Parse(ds1.Tables[0].Rows[i]["sid"].ToString());
            MyVector omv = new MyVector(omid);
            double sim = MyVec.GetSim(omv);
            ArrayList oarr = omv.GetRank();
            Label orank = new Label();
            orank.Width = 540;
            orank.Text = omid + ":{";
            for (j = 0; j < oarr.Count; j++)
            {
                orank.Text += oarr[j] + " ";
            }
            orank.Text += "}";
            PanelRank.Controls.Add(orank);
            Label lab = new Label();
            lab.Text = "与向量sid=" + omid + "的相似度：" + sim;
            if (double.Parse(ds2.Tables[0].Rows[0][0].ToString()) <= sim) lab.Text += "(被选择)";
            lab.Width = 540;
            PanelSim.Controls.Add(lab);
        }
        MyVec.Recommand(double.Parse(ds2.Tables[0].Rows[0][0].ToString()));
        MyVector mvreco = MyVec.GetRecommand();
        for (i = 0; i < mvreco.GetLength(); i++)
            if (mvreco.GetIname(i) == cname)
            {
                LabelResult.Text = cname + ":" + mvreco.GetValue(i);
                break;
            }
    }
}